﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace block_explorer.Shaders
{
    class Render2DEffect
    {
        private const string sEffectFilename = "Effects/2DRender";
        private const string sDepthMapParameterName = "DepthMap";
        private const string sWorldParameterName = "World";
        private const string sViewParameterName = "View";
        private const string sProjectionParameterName = "Projection";
        private const string sDefaultTechniqueName = "Technique1";

        private Effect mEffect;

        private EffectParameter mDepthMap;
        private EffectParameter mWorldMatrix;
        private EffectParameter mViewMatrix;
        private EffectParameter mProjectionMatrix;

        public Texture DepthMap { set { mDepthMap.SetValue(value); } }
        public Matrix World { set { mWorldMatrix.SetValue(value); } }
        public Matrix View { set { mViewMatrix.SetValue(value); } }
        public Matrix Projection { set { mProjectionMatrix.SetValue(value); } }

        public EffectPassCollection Passes { get { return mEffect.CurrentTechnique.Passes; } }

        public Render2DEffect(GraphicsDevice device, ContentManager content)
        {
            mEffect = content.Load<Effect>(sEffectFilename);
            mDepthMap = mEffect.Parameters[sDepthMapParameterName];
            mWorldMatrix = mEffect.Parameters[sWorldParameterName];
            mViewMatrix = mEffect.Parameters[sViewParameterName];
            mProjectionMatrix = mEffect.Parameters[sProjectionParameterName];

            mEffect.CurrentTechnique = mEffect.Techniques[sDefaultTechniqueName];
        }
    }
}
